# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="james"
__date__ ="$28/04/2011 8:53:21 PM$"

from libraries.resource import load_image
import pygame
from pygame.sprite import Sprite
from weapons.Weapon import Weapon

class Bullet(Sprite):
    speed = 10
    damage = 100
    def __init__(self,weapon):
        Sprite.__init__(self)
        self.weapon = weapon
        self.draw_bullet()
        self.rect.midtop = self.weapon.player.rect.midtop
        self.rect.top = self.rect.top
        self.other_sprites = self.weapon.stage.all_sprites.copy()
        self.other_sprites.remove(self)
        self.other_sprites.remove(self.weapon.player)

    def update(self):
        self.fly()

    def draw_bullet(self):
        self.image, self.rect = load_image('bullet.jpeg', -1)

    def fly(self):
        self.rect.top = self.rect.top - self.speed
        if self.rect.top < 0:
            self.kill()
        hit_targets = pygame.sprite.spritecollide(self, self.other_sprites, False)
        if len(hit_targets) > 0:            
            self.hit_target(hit_targets)

    def hit_target(self,targets):
        for target in targets:
            target.take_hit(self.damage)
        self.kill()
